package com.hrpmar.service.impl;

import com.hrpmar.controller.dto.ProviderDto;
import com.hrpmar.mapper.ProviderMapper;
import com.hrpmar.pojo.Provider;
import com.hrpmar.service.ProviderService;
import com.hrpmar.utils.Pager;
import com.hrpmar.utils.StringFormat;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dell on 2017/11/17.
 * 供应商实现类
 */
@Service("providerService")
@Transactional
public class ProviderServiceImpl implements ProviderService {

    @Resource
    private ProviderMapper providerMapper;


    //条件模糊查询
    @Override
    public Pager getProviderByDto(Integer offset, Integer limit, ProviderDto dto) {
        Pager pager = new Pager();
        pager.setTotal(providerMapper.getTotal(dto));
        List<Provider> list = providerMapper.getProviderByDto(offset,limit,dto);
        for (Provider p:list){
            p.setProName(StringFormat.StringFormat(p.getProName(),10));
            p.setProReaddress(StringFormat.StringFormat(p.getProReaddress(),10));
            p.setProPractice(StringFormat.StringFormat(p.getProPractice(),10));
        }
        pager.setRows(list);
        return pager;
    }

    //增加
    @Override
    public void addPro(Provider provider) {
        providerMapper.addPro(provider);
    }

    //修改
    @Override
    public void updatePro(Provider provider) {
        providerMapper.updatePro(provider);
    }

    @Override
    public void delPro(Integer id) {
        providerMapper.delPro(id);
    }

    @Override
    public Provider getProviderById(Integer id) {
        return providerMapper.getProviderById(id);
    }
}
